package com.gopay.bis.dao.bankorder.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gopay.bis.dao.bankorder.BankAuthOrderDAO;
import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.domain.bank.BankAuthOrder;
import com.gopay.common.util.DateUtils;

/** 
 * 委托代收认证DAO实现
 * @ClassName: BankAuthOrderDAOImpl 
 * @author w_jiqing 
 * @date 2017年2月10日 下午1:22:58  
 */ 
@Repository(value = "bankAuthOrderDAO")
public class BankAuthOrderDAOImpl extends BaseDAOImpl<BankAuthOrder, String> implements BankAuthOrderDAO{


    @Override
    public int updateBackStatus(BankAuthOrder authOrder) {
        
        Date curDate = DateUtils.getSystemDate();

        StringBuffer hql = new StringBuffer();
        hql.append("update BankAuthOrder set orderStatus = :orderStatus ,");
        hql.append("lastUpdTs = :lastUpdTs ");
        hql.append("where orderId = :orderId ");
        
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("orderStatus", authOrder.getOrderStatus());
        params.put("lastUpdTs", curDate);
        params.put("orderId", authOrder.getOrderId());

        return this.updateByHql(hql.toString(), params);
    }

    @Override
    public int updateBankOrderIdByOrderId(BankAuthOrder authOrder) {
        Date curDate = DateUtils.getSystemDate();
        
        StringBuffer hql = new StringBuffer();
        hql.append("update BankAuthOrder set outOrderId = :outOrderId  ,");
        hql.append("lastUpdTs = :lastUpdTs ");
        hql.append("where orderId = :orderId ");
        
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("outOrderId", authOrder.getOutOrderId());
        params.put("lastUpdTs", curDate);
        params.put("orderId", authOrder.getOrderId());

        return this.updateByHql(hql.toString(), params);
    }

    @Override
    public BankAuthOrder findAuthBankOrderByBankId(String bankOrderId) {
        String hql = "from BankAuthOrder where outOrderId=:outOrderId";
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("outOrderId", bankOrderId);
        List<BankAuthOrder> authOrders = this.findByHql(hql, param);
        if (authOrders != null && authOrders.size() != 0) {
            return authOrders.get(0);
        } else {
            return null;
        }
    }
    





}
